﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace csvformater.Gardgets
{
    /// <summary>
    /// Tables.xaml 的交互逻辑
    /// </summary>
    public partial class Tables : UserControl
    {
        private int _index = 0;
        public Tables()
        {
            InitializeComponent();
        }
        public void AddNewTab(string title,ref TableSingleton tableSingleton )
        {
            try
            {
                this._index++;
                var tabItem = new TabItem();
                tabItem.Header = title;
                tabItem.Content = tableSingleton;
                tableContainer.Items.Add(tabItem);
                
            }
            catch (Exception)
            {
                _index--;
                throw new Exception("Fail to add new tab");
            }
        }
        public void DelTab()
        {
            try
            {
                _index--;
                tableContainer.Items.RemoveAt(_index);
            }
            catch (Exception)
            {
                _index++;
                throw new Exception("Fail to remove tab");
            }
            
        }
    }
}
